<!--- ==================================================
NAME:	upd_contact.cfm
DESC:	File used to update a contact.
=================================================== --->
<cfsetting enablecfoutputonly="yes">

<!--- default data --->
<cfparam name="arguments.customerid" type="any" default="">
<cfparam name="arguments.contactid" type="any" default="">
<cfparam name="arguments.type" type="any" default="">
<cfparam name="arguments.prefix" type="any" default="">
<cfparam name="arguments.first_name" type="any" default="">
<cfparam name="arguments.midinit" type="any" default="">
<cfparam name="arguments.last_name" type="any" default="">
<cfparam name="arguments.company_department" type="any" default="">
<cfparam name="arguments.b_company_name" type="any" default="">
<cfparam name="arguments.b_address1" type="any" default="">
<cfparam name="arguments.b_address2" type="any" default="">
<cfparam name="arguments.b_city" type="any" default="">
<cfparam name="arguments.b_state" type="any" default="">
<cfparam name="arguments.b_zip" type="any" default="">
<cfparam name="arguments.b_geo_code" type="any" default="">
<cfparam name="arguments.b_country" type="any" default="">
<cfparam name="arguments.b_phone" type="any" default="">
<cfparam name="arguments.b_ext" type="any" default="">
<cfparam name="arguments.alt_phone" type="any" default="">
<cfparam name="arguments.alt_ext" type="any" default="">
<cfparam name="arguments.fax_phone" type="any" default="">
<cfparam name="arguments.email" type="any" default="">
<cfparam name="arguments.source" type="any" default="web">
<cfparam name="arguments.account_active" type="any" default="">
<cfparam name="arguments.tax_resale_number" type="any" default="">
<cfparam name="arguments.tsr_own" type="any" default="">
<cfparam name="arguments.interface_type" type="any" default="">

<!--- 
		Defect 2104 alter the opt-out flags
		ESF now handles Advertising Opt-Out - "Y" means yes to broadcast
		NMail handles Confirmation Opt-Out - "Y" means no email should be sent
--->
<cfparam name="arguments.flag_esf" type="any" default="">
<cfif arguments.flag_esf is "Y">
	<cfset arguments.flag_esf = "<esf>Y</esf>">
<cfelseif arguments.flag_esf is "N">	
	<cfset arguments.flag_esf = "<esf>N</esf>">
</cfif>

<cfparam name="arguments.flag_nmail" type="any" default="">
<cfif arguments.flag_nmail is "Y">
	<cfset arguments.flag_nmail = "<no_email>Y</no_email>">
<cfelseif arguments.flag_nmail is "N">	
	<cfset arguments.flag_nmail = "<no_email>N</no_email>">
</cfif>

<!--- clean data --->
<cfset arguments.first_name="#application.string_validation.replace_and(arguments.first_name)#">
<cfset arguments.last_name="#application.string_validation.replace_and(arguments.last_name)#">
<cfset arguments.company_department="#application.string_validation.replace_and(arguments.company_department)#">
<cfset arguments.b_company_name="#application.string_validation.replace_and(arguments.b_company_name)#">
<cfset arguments.b_address1="#application.string_validation.replace_and(arguments.b_address1)#">
<cfset arguments.b_address2="#application.string_validation.replace_and(arguments.b_address2)#">
<cfset arguments.b_city="#application.string_validation.replace_and(arguments.b_city)#">
<cfset arguments.b_state="#application.string_validation.replace_and(arguments.b_state)#">
<cfset arguments.b_phone="#application.string_validation.only_numeric(arguments.b_phone)#">
<cfset arguments.alt_phone="#application.string_validation.only_numeric(arguments.alt_phone)#">
<cfset arguments.fax_phone="#application.string_validation.only_numeric(arguments.fax_phone)#">


<!--- build xml statement --->
<cfscript>
xi_namespace='#trim(application.xi_namespace)#:CUSTOMER:UpdateContact';
xi_interface='UpdateContact_OB';
if(trim(arguments.interface_type) eq "")
{
	xmlCustomer = '<customer>
			<customerid>#arguments.customerid#</customerid>
			<contactid>#arguments.contactid#</contactid>
			<type>#ucase(arguments.type)#</type>
			<prefix>#ucase(arguments.prefix)#</prefix>
			<first_name>#ucase(arguments.first_name)#</first_name>
			<midinit>#ucase(arguments.midinit)#</midinit>
			<last_name>#ucase(arguments.last_name)#</last_name>
			<abinum>#ucase(arguments.abinum)#</abinum>
			<company_department>#Ucase(arguments.company_department)#</company_department>
			<company_division></company_division>
			<billing>
				<company_name>#Ucase(arguments.b_company_name)#</company_name>
				<address_1>#ucase(arguments.b_address1)#</address_1>
				<address_2>#ucase(arguments.b_address2)#</address_2>
				<city>#ucase(arguments.b_city)#</city>
				<state>#ucase(arguments.b_state)#</state>
				<zip>#ucase(arguments.b_zip)#</zip>
				<geo_code>#Ucase(arguments.b_geo_code)#</geo_code>
				<country>#ucase(arguments.b_country)#</country>
				<phone>#arguments.b_phone#</phone>
			</billing>
			<ext>#arguments.b_ext#</ext>
			<alt_phone>#arguments.alt_phone#</alt_phone>
			<alt_ext>#arguments.alt_ext#</alt_ext>
			<fax_phone>#arguments.fax_phone#</fax_phone>
			<email>#arguments.email#</email>
			#arguments.flag_esf#
			#arguments.flag_nmail#
		</customer>';
}
else
{
	xmlCustomer = '<interfacetype>#arguments.interface_type#</interfacetype>
					<customer>
						<customerid>#arguments.customerid#</customerid>
						<tsr_own>#arguments.tsr_own#</tsr_own>
					</customer>
				';
}

xml = '<xtiinput>
	<inputheader>
		<actionset>
			<action>upd_contact</action>
		</actionset>
	</inputheader>
	<inputdata>
		<system>#variables.system#</system>
		#xmlCustomer#
	</inputdata>
</xtiinput>';
</cfscript>